
export default {

  data () {
    return {
      // 商品列表数据
      goodsList: [],
      // 当前页
      pagenum: 1,
      // 每页大小
      pagesize: 5,
      // 总条数
      total: 0
    }
  },
  created () {
    // 获取路由参数 （分页）
    const curPage = this.$route.params.page
    console.log(curPage)
    this.getGoodsList(curPage)
  },
  // 获取分页数据
  methods: {
    async getGoodsList (pagenum = 1) {
      const res = await this.$http.get('/goods', {
        // 传递get参数
        params: {
          pagenum,
          pagesize: this.pagesize,
          query: ''
        }
      })
      // console.log(res.data)
      const { goods, pagenum: curPage, total } = res.data.data
      this.pagenum = curPage - 0
      this.goodsList = goods
      this.total = total
    },
    /**
     * 切换分页
     */
    changePage (curPage) {
      // 获取当前页数据
      // 修改路由（跳转页面）
      this.getGoodsList(curPage)
      this.$router.push(`/goods/${curPage}`)
    }
  },
  watch: {
    '$route' (to, from) {
      this.getGoodsList(to.params.page)
    }
  }
}
